package main.RandomIO;

import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;

public class RandIO {
    public static void main(String[] args) {
        try{
            randOutput();
        }catch (Exception e){
            e.printStackTrace();
        }

    }
    public static void randInput() throws Exception{
        RandomAccessFile f = new RandomAccessFile("data//rr.txt","rw");
        f.seek(10);
        byte[] b = new byte[1024];
        int len = 0;
        while((len = f.read(b))!=-1){
            System.out.println(new String(b,0,len));
        }
        f.close();
    }
    public static void randOutput() throws Exception{
        //在中间写，会覆盖掉等长的原内容
        RandomAccessFile f = new RandomAccessFile("data//rr.txt","rw");
        String str = "ha哈";
        //f.seek(0);
        f.seek(f.length());//在文件末尾追加
        f.write(str.getBytes(StandardCharsets.UTF_8));
        f.close();
    }
}
